package amis

type Obj map[string]interface{}

type Options map[string]interface{}

type MultiOptions map[string]Options

type BaseQuery struct {
	Page     int    `form:"page"`
	PerPage  int    `form:"perPage"`
	OrderBy  string `form:"orderBy"`
	OrderDir string `form:"orderDir"`
	Keywords string `form:"keywords"`
}

type PageData struct {
	Items interface{} `json:"items,omitempty"`
	Total int64       `json:"total,omitempty"`
}

type Template struct {
	Type string `json:"type,omitempty"`
	Tpl  string `json:"tpl,omitempty"`
}

func New(t string) Obj {
	return map[string]interface{}{
		"type": t,
	}
}

func NewAction(t string) Obj {
	return map[string]interface{}{
		"type":       "button",
		"actionType": t,
	}
}

func (o Obj) Set(key string, val interface{}) Obj {
	o[key] = val
	return o
}

func (o Obj) SetWhere(key string, value interface{}, lamda func() bool) Obj {
	if lamda() {
		o[key] = value
	}
	return o
}

func (o Obj) SetOptions(opts Options) Obj {
	if opts == nil {
		return o
	}
	for k, v := range opts {
		o[k] = v
	}
	return o
}
